#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5;
int t,n,m,a[N + 5],c[N + 5],p[N + 5];
int f(int n){
	for (int i = 1;i <= n;i ++)
		if (pow(2,i) >= n) return i;
	return 0;
}
signed main(){
	freopen ("arena.in","r",stdin);
	freopen ("arena.out","w",stdout);
	while (cin >> n >> m){
		for (int i = 1;i <= n;i ++) cin >> a[i];
		for (int i = 1;i <= m;i ++) cin >> c[i];
		int k = f(n);
		for (int i = 1;i <= pow(2,k - i);i ++){
			char ch;
			cin >> ch;
		}
		int tt;
		cin >> tt;
		for (int i = 1;i <= tt;i ++){
			for(int j = 1;j <= 4;j ++){
				int x0,x1,x2,x3;
				cin >> x0 >> x1 >> x2 >> x3;
			}
			cout << 1 << endl;
		}
	}
	return 0;
}
